var str2 = "0-1000";
var arr = ["0-1000","0-30","30-50","50-80","80-100","100-150","150-200","200-1000"],
	arr2 = ["","一室","二室","三室","四室","五室","五室以上"];
angular.module("myApp")
.controller("ershouController",["$scope","ershouService","$state","$stateParams",function($scope,ershouService,$state){
	ershouService.getData().success(function(res){
		console.log(res.data);
		$scope.items = res.data.rows;
	});
	ershouService.getData2().success(function(res1){
		console.log(res1);
		$scope.item1 = res1.data;
	});
	$scope.dex = 0;
	$scope.orderKey="";
	$scope.flag=false;
	$scope.flag2=false;
	$scope.flag3=false;
	$scope.flag4=false;
	//点击位置选项 弹出右侧地址选项
	$scope.fn = function(index){
		$scope.dex = index;
		if($scope.item1.destination[index].place.length==0){
			$scope.flag=false;
		}
	}

	$scope.f2 = function(key){
		$scope.orderKey = key;
		console.log(key);
	}
	
	$scope.searchKey="";
	$scope.searchKey2="";

	//过滤地址
	$scope.fil = function($event){
		if($event.target.innerHTML=="不限"){
			$scope.searchKey = "";
			$scope.searchKey2 = "";
			$scope.flag = false;
		}else{
			$scope.searchKey = $event.target.innerHTML;
		}	
		console.log($scope.searchKey);
	}
	//户型点击过滤函数
	// $scope.f3 = function($event){
	// 	var index = $event.target.getAttribute("index");
		
	// 	$scope.searchKey2 = arr2[index];
		
	// 	$scope.flag2 = false;
	// }

	// $scope.f4 = function($event){
	// 	var index = $event.target.getAttribute("index");
	// 	str2 = arr[index];
	// 	$scope.flag3=false;
	// }
	
	// 	console.log($scope.searchKey);
	// }
	//户型点击过滤函数
	$scope.f3 = function($event){
		var index = $event.target.getAttribute("index");
		
		$scope.searchKey2 = arr2[index];
		
		$scope.flag2 = false;
	}

	$scope.f4 = function($event){
		var index = $event.target.getAttribute("index");
		str2 = arr[index];
		$scope.flag3=false;
	}

	$scope.jump = function(){
		window.location.href="views/home/detail.html"
           
	}

	if(window.localStorage.address){
		$scope.searchKey = window.localStorage.address;
		console.log($scope.searchKey);
	}

	
}])
//自定义过滤器 过滤楼房价格
.filter('mayfilter',function(){
    return function(obj){
    if (obj==undefined) {
        return;
    }
    var splitD=str2.split(/\-/);
        var listData=[];
        for (var i = 0; i < obj.length; i++) {
             if ((parseInt(splitD[0]) <= parseInt(obj[i].jprice)) && (parseInt(obj[i].jprice)<=parseInt(splitD[1]))) {
                 listData.push(obj[i]);
             }
        };
        return listData;
    }
}) 